<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://unpkg.com/vue@2.7.14/dist/vue.min.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css"></script>
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
</head>
<body>
<div id="app">
    <el-container>
        <el-container>
            <el-aside style="width: 200px">
                <el-menu @select="selectMenu"
                         default-active="2"
                         class="el-menu-vertical-demo">
                    <el-menu-item v-for="menu in menus" :index="menu.name">
                        <i class="el-icon-location"></i>
                        <span>{{menu.name}}</span>
                    </el-menu-item>
                </el-menu>
            </el-aside>
            <el-main style="overflow: hidden">
                <el-tabs type="border-card" style="height: 100%">
                    <el-tab-pane v-for="tab in tabs" :label="tab.name"
                                 :key="tab.name" :name="tab.name">
                        <iframe :src="tab.url" height="100%" width="100%"></iframe>
                    </el-tab-pane>
                </el-tabs>
            </el-main>
        </el-container>
    </el-container>
    <br>
</div>
<script>
    var v=new Vue({
        el:"#app",
        data:{
            menus:[
                {name:"比赛结果",url:"result.html"},
                {name:"赛后数据",url:"statistics.html"},
                {name:"队伍详情",url:"teams.html"},
            ],
            tabs:[],
            currentTab:""
        },
        methods:{
            selectMenu(name){
                //查找是否已经打开该页
                let tab=this.tabs.find(tab=>{
                    if(tab.name == name){
                        return tab;
                    }
                });
                //如果tab不为undifined,表示已经打开tab
                if(tab){
                    //直接选中该标签
                    this.currentTab = name;
                    return;
                }
                this.menus.forEach(menu=>{
                    if(menu.name==name){
                        this.tabs.push({
                            name: name,
                            url:menu.url
                        });
                        //设置当前页
                        this.currentTab =name;
                    }
                });
            }
        }
    });
</script>
</body>
</html>
<style>
    html,body,#app{
        padding: 0px;
        margin: 0px;
        height: 100%;
    }
    .el-container{
        height: 100%;
    }
    .el-tabs__content{
        height: calc(100% - 68px);
    }
    .el-tab-pane{
        height: 100%;
    }


</style>